<?php
/*
* $Author ：PHPYUN开发团队
*
* 官网: http://www.phpyun.com
*
* 版权所有 2009-2019 宿迁鑫潮信息技术有限公司，并保留所有权利。
*
* 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class zphnet_model extends model{

    /**
	 * @desc   获取网络招聘会列表
	 * @param  $whereData:查询条件
	 * @param  $data:自定义处理数组 
	 */
	public function getList($whereData , $data = array('field'=>null,'utype'=>null)) {  
		
		$select		=	$data['field'] ? $data['field'] : '*';
		
		$List		=   $this -> select_all('zphnet',$whereData,$select);
		
		if($List&&is_array($List)){
			
		    if ($data['utype'] == 'admin'){
		        
		        foreach($List as $key => $val){
		            
		            $zid[]	=	$val['id'];
		            
		            $List[$key]['comnum']	=	'0';
		            $List[$key]['booking']	=	'0';
		        }
		        
		        $all	 =	$this->select_all('zphnet_com',array('zid'=>array('in',pylode(',', $zid)),'groupby'=>'zid'),'zid,count(*) as num');
		        
		        $status  =	$this->select_all('zphnet_com',array('zid'=>array('in',pylode(',', $zid)),'status'=>'0','groupby'=>'zid'),'`zid`,count(*) as num');
		        
		        foreach($List as $key => $v){
		            
		            foreach($all as $val){
		                
		                if($v['id'] == $val['zid']){
		                    $List[$key]['comnum']	=	$val['num'];
		                }
		            }
		            foreach($status as $val){
		                
		                if($v['id'] == $val['zid']){
		                    $List[$key]['booking']	=	$val['num'];
		                }
		            }
		            if($v['did']<1){
		                $List[$key]['did']	=	'0';
		            }
		        }
		    }
		    if ($data['utype'] == 'wxapp'){
		        
		        $time  =  time();
		        
		        foreach($List as $key => $val){
		            $List[$key]['starttime']  =  date('Y-m-d H:i',strtotime($val['starttime']));
		            $List[$key]['endtime']    =  date('Y-m-d H:i',strtotime($val['endtime']));
		            $List[$key]['stime']      =  strtotime($val['starttime'])-$time;
		            $List[$key]['etime']      =  strtotime($val['endtime'])-$time;
		        }
		    }
		}
		return $List;
	}    
	
	/**
	* @desc 获取招聘会列表详细信息
	*/
	public function getInfo($whereData,$data = array())
	{
        $select  =  $data['field'] ? $data['field'] : '*';

        $Info    =  $this -> select_once('zphnet', $whereData, $select); 

        if (!empty($Info)) {
            
            if (!empty($Info['starttime'])) 
            {
                $Info['starttime_n']  =  date('Y-m-d H:i',strtotime($Info['starttime']));
                $Info['stime']      =  strtotime($Info['starttime']) - time();
            }
            
            if (!empty($Info['endtime'])) 
            {
                $Info['endtime_n']  =  date('Y-m-d H:i',strtotime($Info['endtime']));
                $Info['etime']    =  strtotime($Info['endtime']) - time();
            }

            if (!empty($Info['body'])){
                
                $body  =  str_replace(array('&quot;','&nbsp;','<>'), array('','',''), $Info['body']);
                $body  =  htmlspecialchars_decode($body);
                
                preg_match_all('/<img(.*?)src=("|\'|\s)?(.*?)(?="|\'|\s)/',$body,$res);
                if(!empty($res[3])){
                    foreach($res[3] as $v){
                        if(strpos($v,'http:')===false && strpos($v,'https:')===false){
                            $body  =  str_replace($v,$this->config['sy_ossurl'].$v,$body);
                        }
                    }
                }
                $Info['body']  =  $body;
            }
            if (!empty($Info['pic'])) { // 缩略图
                $Info['pic_n']  =  checkpic($Info['pic'], $this->config['sy_zph_icon']);
            }

            if (!empty($Info['banner'])) { // 横幅
                $Info['banner_n']  =  checkpic($Info['banner'], $this->config['sy_zphbanner_icon']);
            }
        }
        return $Info;
    }
	
	/**
	* @desc 添加招聘会
	*/
	public function addInfo($data	=	array()){
		
		$AddData	=	array(
			'title'		 =>	 $data['title'],
			'address'	 =>	 $data['address'],
			'phone'		 =>	 $data['phone'],
			'starttime'  =>	 $data['starttime'],
			'endtime'	 =>	 $data['endtime'],
			'body'		 =>	 $data['body'],
			'ctime'		 =>	 time(),
			'did'	     =>	 $data['did'],
		    'toptitle'   =>  $data['toptitle'],
		    'zw'         =>  $data['zw']
		);
		if($data['pic']){

			$AddData['pic']	=	$data['pic'];
		}
		if($data['banner']){

			$AddData['banner']	=	$data['banner'];
		}
		if ($AddData && is_array($AddData)){
			
			$nid	=	$this -> insert_into('zphnet',$AddData);
		}
		return $nid;
	}
	
	/**
	* @desc 修改招聘会
	*/
	public function upInfo($whereData, $data = array()){
		
		if(!empty($whereData)) {
			
			$PostData	=	array(
				'title'		 =>	 $data['title'],
				'phone'		 =>	 $data['phone'],
				'starttime'  =>	 $data['starttime'],
				'endtime'	 =>	 $data['endtime'],
				'body'		 =>	 $data['body'],
				'did'		 =>	 $data['did'],
			    'toptitle'   =>  $data['toptitle'],
			    'zw'         =>  $data['zw']
			);
			if($data['pic']){

				$PostData['pic']	=	$data['pic'];

			}
			if($data['banner']){

				$PostData['banner']	=	$data['banner'];

			}
			
			if ($PostData && is_array($PostData)){
				
				$nid	=	$this -> update_once('zphnet',$PostData,array('id'=>$whereData['id']));
			
			}
			return $nid;
		}
	}

	/**
	* @desc 删除招聘会
	*/
	public function delZph($delId){
	    
        if (empty($delId)) {

            $return     =   array( 'errcode' => 8, 'msg' => '请选择要删除的数据！');
        
        } else {

            if (is_array($delId)) {

                $delId  =   pylode(',', $delId);
                
                $return['layertype']    =   1;
                
            } else {

                $return['layertype']    =   0;
            }

            $delid      =   $this -> delete_all('zphnet', array('id' => array('in', $delId)), '');

            if ($delid) {

                $this -> delete_all('zphnet_com', array('zid' => array('in', $delId)), '');
                $this -> delete_all('zphnet_look', array('zid' => array('in', $delId)), '');
                $this -> delete_all('zphnet_user', array('zid' => array('in', $delId)), '');
            }
            $return['msg']      =   '网络招聘会';

            $return['errcode']  =   $delid ? '9' : '8';

            $return['msg']      =   $delid ? $return['msg'].'删除成功！' : $return['msg'].'删除失败！';
        }

        return $return;
    }
	
	/**
	* @desc 获取参会企业列表
	*/
	public function getZphnetComList($whereData , $data=array('utype'=>''))
	{
	    $select  	=  	$data['field'] ? $data['field'] : '*';
		
	    $List		=	$this -> select_all('zphnet_com' , $whereData, $select);
		
	    if(!empty($List)){
			
		    $uid  =  $zid  =  array();
		    
			foreach($List as $v){
				if($v['uid'] && !in_array($v['uid'] , $uid)){
					$uid[]  =  $v['uid'];
				}
				if($v['zid'] && !in_array($v['zid'],$zid)){
				    $zid[]  =  $v['zid'];
				}
			}
			if ($data['utype'] == 'admin'){
			    
			    $company  =  $this -> select_all('company', array('uid'=>array('in',pylode(',',$uid))),'`uid`,`name`,`logo`,`logo_status`,`r_status`');
			    
			    $jfield   =  '`id`,`uid`,`name`';
			    
			    $listA	  =  $this -> select_all('company_job',array('uid'=>array('in',pylode(',',$uid)),'state' => 1, 'status' => 0,'r_status' => 1),$jfield);
			}
 			
			$zph	  =  $this -> select_all('zphnet',array('id'=>array('in',pylode(',',$zid))),'`id`,`title`,`starttime`,`endtime`');
			
			foreach($List as $k => $v){
			    
			    $List[$k]['bmctime_n']	=	date('Y-m-d',$v['ctime']);
			    
			    if ($data['utype'] == 'admin'){
			        foreach($company as $val){
			            
			            if($v['uid'] == $val['uid']){
			                
			                $List[$k]['comname']	=	$val['name'];
			            }
			        }
			        $jobname	=	array();
			        
			        foreach($listA as $val){
			            
			            if ($v['uid'] == $val['uid']) {
			                if (count($jobname) < 10){
			                    $jobname[]		      =  $val['name'];
			                    $List[$k]['jobname']  =  @implode('、',$jobname);
			                }
			            }
			        }
			    }
				foreach($zph as $val){
				    
				    if($v['zid'] == $val['id']){
				        $List[$k]['zphname']	=	$val['title'];
				        $List[$k]['title']		=	$val['title'];
				        $List[$k]['starttime']	=	$val['starttime'];
				        $List[$k]['endtime']	=	$val['endtime'];
				        if(strtotime($val['starttime'])>time()){
				            $List[$k]['notstart']	=	1;
				        }
				    }
				}
			}
		}
		return $List;
	}
	// 
	function getAreaComList($whereData, $data = array('zwFirst'=>false,'utype'=>'','keyword'=>''))
	{
	    if ($data['utype'] == 'wap'){
	        
	        $whereData['status']   =  1;
	        if (empty($whereData['orderby'])){
	            $whereData['orderby']  =  'zw,desc';
	        }
	        
	        if ($data['keyword'] != ''){
	            unset($whereData['limit']);
	        }
	        
	        $comlist  =  $this->select_all('zphnet_com', $whereData);
	        
	    }else{
	        // 非首次展示时，有选择区域，按区域查询
	        if (!empty($whereData['zw']) && !$data['zwFirst']){
	            
	            $area  =  $this->select_once('zphnet_class',array('id'=>$whereData['zw']));
	            
	        }else{
	            // 首次展示，如参会企业数量小于50，展示全部参会企业
	            if ($data['zwFirst']){
	                
	                $area['id']  =  -1;
	                
	            }else{
	                $area['id']  =  0;
	            }
	        }
	        
	        $uid  =  $other  =  array();
	        
	        $zphWhere  =  array(
	            'zid'      =>  $whereData['zid'],
	            'status'   =>  1,
	            'orderby'  =>  'zw,desc'
	        );
	        // 关键词搜索时查询全部，不限展位区域
	        if ($data['keyword'] == '' && $area['id'] > -1){
	            $zphWhere['zw']  =  $area['id'];
	        }
	        
	        $comlist  =  $this->select_all('zphnet_com', $zphWhere);
	        // 刚展示时首个类别下没有企业，先展示未分配的企业
	        if (empty($comlist) && $data['zwFirst']){
	            
	            $comlist  =  $this->select_all('zphnet_com', array('zid'=>$whereData['zid'],'zw'=>0,'status'=>1,'orderby'=>'zw,desc'));
	            $area['firstNum']  =  0;
	        }else{
	            $area['firstNum']  =  count($comlist);
	        }
	    }
	    if (!empty($comlist)){
	        
	        foreach($comlist as $v){
	            if($v['uid'] && !in_array($v['uid'] , $uid)){
	                $uid[]  =  $v['uid'];
	            }
	        }
	        $jfield   =  '`id`,`uid`,`name`,`exp`,`edu`,`sex`,`age`,`marriage`,`minsalary`,`maxsalary`';
	        $job      =  $this->select_all('company_job', array('uid'=>array('in',pylode(',',$uid)),'state'=>1,'status'=>0,'r_status'=>1),$jfield);
	        
	        $comWhere['uid']  =  array('in',pylode(',',$uid));
	        if ($data['keyword'] != ''){
	            $comWhere['name']  =  array('like',$data['keyword']);
	        }
	        $company  =  $this->select_all('company', $comWhere, '`uid`,`name`,`shortname`,`logo`,`logo_status`,`r_status`');
	        
	        include_once ('cache.model.php');
	        $cacheM  =  new cache_model($this->db, $this->def);
	        $cache   =  $cacheM -> GetCache('com');
	        
	        foreach ($company as $k=>$v){
	            
	            if ($v['shortname']){
	                $company[$k]['comname']  =  $v['shortname'];
	            }else{
	                $company[$k]['comname']  =  $v['name'];
	            }
	            if ($v['logo_status'] == 0){
	                $company[$k]['logo']  =  checkpic($v['logo'],$this->config['sy_unit_icon']);
	            }else{
	                $company[$k]['logo']  =  checkpic($this->config['sy_unit_icon']);
	            }
	            foreach ($job as $val){
	                
	                if ($v['uid'] == $val['uid']){
	                    
	                    $company[$k]['job'][]  =  $this->jobData($val, $cache);
	                }
	            }
	        }
	        foreach ($company as $k=>$v){
	            $company[$k]['jobnum']  =  count($v['job']);
	            foreach ($v['job'] as $key=>$val){
	                if ($key > 4){
	                    unset($company[$k]['job'][$key]);
	                }
	            }
	        }
	        $area['com']  =  $company;
	    }
	    
	    return $area;
	}
	private function jobData($job, $cache){
	    
	    $name  =  $cache['comclass_name'];
	    $sex   =  $cache['com_sex'];
	    
	    $data  =  array(
	        'id'=>$job['id'],
	        'uid'=>$job['uid'],
	        'name'=>$job['name']
	    );
	    
	    if (!empty($job['minsalary']) || !empty($job['maxsalary'])) {
	        
	        if(!empty($job['minsalary']) && !empty($job['maxsalary'])){
	            
	            $data['job_salary']  =  '￥'.$job['minsalary'].'-'.$job['maxsalary'];
	            
	        }elseif (!empty($job['minsalary'])){
	            
	            $data['job_salary']  =  '￥'.$job['minsalary'];
	            
	        }else{
	            
	            $data['job_salary']  =  '面议';
	        }
	    }else{
	        
	        $data['job_salary']      =  '面议';
	    }
	    
	    $require  =  array();
	    if (!empty($job['exp'])){
	        
	        $require[]      =  $name[$job['exp']].'经验';
	    }
	    if (!empty($job['edu'])){
	        
	        $require[]      =  $name[$job['edu']].'学历';
	    }
	    if (!empty($job['age'])){
	        
	        $require[]  =  '年龄'.$name[$job['age']];
	    }
	    if (!empty($job['sex'])){
	        
	        $require[]  =  '性别'.$sex[$job['sex']];
	    }
	    if (!empty($job['marriage'])){
	        
	        $marriage  =  $name[$job['marriage']];
	        
	        if ($marriage == '不限'){
	            
	            $require[]  =  '婚况不限';
	            
	        }else{
	            
	            $require[]  =  $marriage;
	        }
	    }
	    $data['require']  =  implode(',', $require);
	    
	    return $data;
	}
	/**
	* @desc 获取参会企业详细信息
	*/
	public function getZphnetCom($whereData,$data	=	array()){
		
		$select		=	$data['field'] ? $data['field'] : '*';
		
		$ZComInfo	=	$this -> select_once('zphnet_com', $whereData, $select);
		
		return $ZComInfo;
	
	}
	/**
	* @desc 获取参会企业数量
	*/
	public function getZphnetComNum($whereData=array(),$data=array()){
		
		return $this -> select_num('zphnet_com', $whereData);
	
	}
	
	/**
	 * @desc 获取参会企业数量总数、职位总数量
	 */
	public function getZphnetAllNum($whereData=array(),$data=array())
	{
	    
	    $com  =  $this->select_all('zphnet_com', $whereData, '`uid`');
	    
	    if (!empty($com)){
	        
	        foreach ($com as $v){
	            
	            $uids[]  =  $v['uid'];
	        }
	        $comnum  =  $this->select_num('company',array('uid'=>array('in',pylode(',', $uids)),'r_status'=>1));
	        
	        $jobnum  =  $this->select_num('company_job',array('uid'=>array('in',pylode(',', $uids)),'state'=>1,'status'=>0,'r_status'=>1));
	    }
	    
	    $usernum  =  $this->select_num('zphnet_user',array('zid'=>$whereData['zid'],'usertype'=>1));
	    
	    $return  =  array(
	        'comnum'   =>  isset($comnum) ? $comnum : 0,
	        'jobnum'   =>  isset($jobnum) ? $jobnum : 0,
	        'usernum'  =>  $usernum
	    );
	    
	    return $return;
	}
	
	/**
	* @desc 添加参会企业
	*/
	public function addZphnetCom($data	=	array()){
		
	    $return   =  array();
		$AddData  =  array(
			'uid'		=>	$data['comid'],
			'zid'		=>	$data['zphid'],
			'ctime'		=>	time(),
			'status'	=>	isset($data['status']) ? $data['status'] : 1
		);
		
		$row  =  $this->select_once('zphnet_com',array('zid'=>$AddData['zid'],'uid'=>$AddData['uid']));
		
		if (!empty($row)){
		    
		    $return['errcode']  =  8;
		    $return['msg']		=  '该企业已参加本次招聘会';
		    
		}else{
		    
		    $nid	=	$this -> insert_into('zphnet_com',$AddData);
		    
		    $return['errcode']  =  9;
		    $return['msg']		=  '添加成功';
		    $return['id']       =  $nid;
		}
		return $return;
	}

	/**
	 * @desc   审核参会企业表信息
	 */
	public  function zphnetComStatus($id , $data = array()){
        $where  =   array();
        
        if (! empty($id)) {
            
            $where['id']    =   array( 'in', pylode(',', $id));
            
            if ($data['status']) {
                
                $updata     =   array('status' => $data['status'],'statusbody' => $data['statusbody']);
                
            }else if ($data['did']) {
                
                $updata     =   array('did' => $data['did']);
            }

            $nid            =   $this->update_once('zphnet_com', $updata, $where);
            
            if (!empty($data['status'])) {
             
                $List           =   $this -> getZphnetComList($where);
    
                /* 消息前缀 */
                $tagName        =   '参会企业';
    
                if (! empty($List)) {
    
                    foreach ($List as $v) {
    
                        $uids[] =   $v['uid'];
    
                        if ($updata['status'] == 2) {
    
                            $statusInfo       =  $tagName . ':<a href="zphnettpl,'.$v['zid'].'">'.$v['comname'].'</a>,审核未通过';
    
                            if ($updata['statusbody']) {
    
                                $statusInfo  .=  ' , 原因：' . $updata['statusbody'];
                            }
    
                            $msg[$v['uid']]   =  $statusInfo;
                            
                        } elseif ($updata['status'] == 1) {
    
                            $msg[$v['uid']]   =  $tagName . ':<a href="zphnettpl,'.$v['zid'].'">'.$v['comname'].'</a>,已审核通过';
                        }
                    }
                    // 发送系统通知
                    include_once ('sysmsg.model.php');
                    $sysmsgM    = new sysmsg_model($this->db, $this->def);
                    $sysmsgM -> addInfo(array('uid' => $uids,'usertype'=>2, 'content' => $msg));
                }
            }
 
            return $nid;
        }
    }
	
	/**
	* @desc  删除参会企业
	*/
	public function delZphnetCom($delId = null,$uid = '', $zid = ''){
	    
        if (empty($delId) || $zid == '') {

            $return         =   array('errcode' => 8, 'msg' => '请选择要删除的数据！');
        } else {

            if (is_array($delId)) {

                $delId                  =   pylode(',', $delId);

                $return['layertype']    =   1;
            } else {

                $return['layertype']    =   0;
            }
            $list  =  $this->select_all('zphnet_com',array('id'=>array('in',$delId)));
            
            if(!empty($list)){
                
                $time    =  time();
                $zphnet  =  $this->select_once('zphnet',array('id'=>$zid));
                
                include_once ('integral.model.php');
                $IntegralM	=  new integral_model($this->db, $this->def);
                
                foreach ($list as $v){
                    
                    $uid[]  =  $v['uid'];
                    // 招聘会未开始， 如果企业报名时花费了积分，删除要退回
                    if ($v['price'] > 0 && strtotime($zphnet['starttime']) < $time){
                        
                        $IntegralM -> company_invtal($v['uid'],2,$v['price'],true,"取消网络招聘会报名",true,2,'integral');//积分操作记录
                    }
                }
                
                $this->delete_all('zphnet_look',array('zid'=>$zid,'comid'=>array('in',pylode(',', $uid))),'');
            }
            
            $return['id']       =   $this -> delete_all('zphnet_com', array('id' => array('in', $delId)), '');
            
            $return['errcode']  =   $return['id'] ? 9 : 8;
            
            $msg                =   '网络招聘会参会企业（ID：'.$delId.'）';
            
            $return['msg']      =   $return['id'] ? $msg.'删除成功！' : '删除失败！';
        }
        return $return;
    }
	
	/**
	 * @desc   招聘会预定
	 */
	public function ajaxZphnet($data = array())
	{
	    
	    $uid        =   intval($data['uid']);
	    $spid		=   intval($data['spid']);
	    $usertype   =   intval($data['usertype']);
	    
	    $did        =   $data['did'] ? intval($data['did']) : $this->config['did'];
	    $zid        =   $data['zid'] ? intval($data['zid']) : '';
	    
	    $time       =   time();
	    $return     =   array();
	    
	    if (empty($uid) || empty($usertype)) {
	        
	        $return['login']    =   1;
	        
	    } else if ($usertype != 2) {
	        
	        $return['msg']      =   '企业用户才可以预定招聘会！';
	        
	    } else {
	        
	        $zph    =   $this->getInfo(array('id' => $zid), array('field' => '`starttime`,`endtime`'));
	        
	        if (strtotime($zph['endtime']) < $time) {
	            
	            $return['msg']  =   '招聘会已经结束！';
	        } else {
	            
	            $cInfo  =  $this->select_once('company',array('uid' => $uid), '`name`,`r_status`');
	            
	            if (empty($cInfo['name'])){
	                
	                $return['msg']	=	'请先完善基本资料！';
	                
	            } elseif ($cInfo['r_status'] != 1) {
	                
	                $return['msg']  =   '您的账号未通过审核，请联系管理员加速审核进度！';
	                
	            } else {
	                
	                $zphcom  =  $this->getZphnetCom(array('uid' => $uid, 'zid' => $zid));
	                
	                if (!empty($zphcom)) {
	                    
	                    if ($zphcom['status'] == 2) {
	                        
	                        $return['msg'] = '您的报名未通过审核，请联系管理员！';
	                    } else {
	                        $return['msg']      = '您已报名该招聘会！';
	                    }
	                } else {
	                    
	                    $suid   =   !empty($spid) ? $spid : $uid;
	                    
	                    require_once ('statis.model.php');
	                    $statisM  =  new statis_model($this->db, $this->def);
	                    $statis   =  $statisM -> getInfo($suid, array('usertype' => $usertype, 'field' => '`rating_type`,`vip_etime`,`zph_num`,`integral`'));
	                    
	                    $com      =  $this->select_once('company',array('uid'=>$uid),'`name`');
	                    
	                    $zData              =   array();
	                    $zData['uid']       =   $uid;
	                    $zData['usertype']  =   $usertype;
	                    $zData['com_name']  =   $com['name'];
	                    $zData['did']       =   $did;
	                    $zData['zid']       =   $zid;
	                    $zData['fuid']      =   $uid;
	                    // 价格
	                    
	                    $price   =  $this->config['integral_zphnet'];
	                    $jifen   =  $price * $this->config['integral_proportion'];
	                    $online  =  $this->config['com_integral_online'];
	                    
	                    if ($price == 0) {
	                        
	                        $return = $this->reserveZphnet($zData);
	                        
	                        return $return;
	                    }
	                    
	                    if ($statis['vip_etime'] >= strtotime('today') || $statis['vip_etime'] == 0) {
	                        
	                        if ($statis['rating_type'] == 1) {
	                            
	                            // 没有招聘会报名次数
	                            if ($statis['zph_num'] == 0) {
	                                
	                                if(empty($spid)){
	                                    
	                                    if ($online != 4) { // 套餐模式
	                                        
	                                        if ($online == 3) { // 积分消费
	                                            
	                                            $return['msg']      =   "您的等级特权已经用完，继续报名将消费 <span style=color:red;>" .$jifen . "</span> ".$this->config['integral_pricename']."，是否继续？";
	                                            $return['url']      =   $this->config['sy_weburl'] . 'wap/member/index.php?c=getserver&id=' . $uid . '&server=15';
	                                            $return['jifen']    =   $jifen;
	                                            $return['integral'] =   intval($statis['integral']);
	                                            $return['pro']      =   $this->config['integral_proportion'];
	                                        } else {
	                                            
	                                            $return['url']      =   $this->config['sy_weburl'] . 'wap/member/index.php?c=getserver&id=' . $uid . '&server=15';
	                                            $return['msg']      =   "您的等级特权已经用完，继续报名将消费 <span style=color:red;>" . $price . "</span> 元，是否继续？";
	                                            $return['price']    =   $price;
	                                        }
	                                    } else {
	                                        
	                                        $return['url']          =   $this->config['sy_weburl'] . 'wap/member/index.php?c=rating';
	                                        $return['msg']          =   "您的等级特权已经用完，可以<a href=\"" . $this->config['sy_weburl'] . "/wap/member/index.php?c=rating\" style=\"color:red;cursor:pointer;\">购买会员</a>！";
	                                    }
	                                    $return['zid']      =   $zid;
	                                    $return['status']   =   2;
	                                }else{
	                                    
	                                    $return['msg']  =   '当前账户套餐余量不足，请联系主账户增配！';
	                                }
	                                
	                            } else {
	                                
	                                $statisM -> upInfo(array('zph_num' => array('-', 1)), array('uid' => $suid, 'usertype' => $usertype));
	                                $return     =   $this->reserveZphnet($zData);
	                            }
	                        } else if ($statis['rating_type'] == 2) {
	                            
	                            // 判断当天是否已达到最大报名次数
	                            require_once ('company.model.php');
	                            $companyM  =  new company_model($this->db, $this->def);
	                            $result    =  $companyM->comVipDayActionCheck('zphnet', $uid);
	                            
	                            if ($result['status'] != 1) {
	                                return $result;
	                            }
	                            
	                            $return         =   $this->reserveZphnet($zData);
	                        }
	                    } else { // 过期会员
	                        
	                        if(empty($spid)){
	                            
	                            if ($online != 4) {
	                                
	                                if ($online == 3) { // 积分消费
	                                    
 	                                    $return['jifen']    =   $jifen;
	                                    $return['integral'] =   intval($statis['integral']);
	                                    $return['pro']      =   $this->config['integral_proportion'];
	                                } else {
	                                    $return['price']    =   $price;
	                                }
	                                $return['msg']      =   "你的会员已到期，请先购买会员！";
	                            } else {
	                                $return['url']  =   $this->config['sy_weburl'] . 'wap/member/index.php?c=rating';
	                                $return['msg']  =   "你的会员已到期，你可以<a href='" . $this->config['sy_weburl'] . "/wap/member/index.php?c=rating' style='color:red;cursor:pointer;'>购买会员</a>！";
	                            }
	                            $return['zid']      =   $zid;
	                            $return['status']   =   2;
	                            
	                        }else{
	                            
	                            $return['msg']  =   '当前账户会员已过期，请联系主账户升级！';
	                        }
	                    }
	                }
	            }
	        }
	    }
	    return $return;
	}
	/**
	 * 修改参会企业
	 * @param array $where
	 * @param array $up
	 */
	public function upZphnetCom($where = array(), $up = array())
	{
	    $return  =  array();
	    if (!empty($where)){
	        
	        $nid  =  $this->update_once('zphnet_com', $up, $where);
	        
	        $return['errcode']	=	$nid ? '9' :'8';
	        $return['msg']		=	$nid ? '参会企业修改成功！' : '修改失败！';
	    }
	    return $return;
	}
	/**
	 * @Desc   网络招聘会报名 
	 *
	 * @param array $data
	 */
	private function reserveZphnet($data = array()){
	   
	    $sql  =  array(
	        'uid'       =>  $data['uid'],
	        'com_name'  =>  $data['com_name'],
	        'zid'       =>  $data['zid'],
	        'ctime'     =>  time(),
	        'status'    =>  0,
	        'did'       =>  $data['did']
	    );
        
	    $nid     =  $this->insert_into('zphnet_com', $sql);
	    $return  =  array();
	    
	    if ($nid){
	        require_once ('log.model.php');
	        $logM  =  new log_model($this->db, $this->def);
	        $logM -> addMemberLog($data['fuid'], $data['usertype'],'报名网络招聘会,ID:'.$data['zid'],14,1);
	        
	        require_once('admin.model.php');
	        $adminM  =  new admin_model($this->db,$this->def);
	        $adminM -> sendAdminMsg(array('first'=>'有新的网络招聘会报名需要审核','type'=>0));
	        
	        $return['status']  =  1;
	        $return['msg']     =  '报名成功,等待管理员审核！';
	        
	    }else{
	        $return['msg']     =  '报名失败,请稍候重试！';
	    }
	    return $return;
	}
	/**
	 * 记录用户进入网络招聘会大厅，同一招聘会不重复记录
	 * @param array $data
	 */
	public function addZphnetUser($data = array()){
	    
	    if (!empty($data['zid']) && !empty($data['uid']) && !empty($data['usertype'])){
	        
	        $row  =  $this->select_once('zphnet_user',array('zid'=>$data['zid'],'uid'=>$data['uid'],'usertype'=>$data['usertype']));
	        
	        if (empty($row)){
	            
	            if ($data['usertype'] == 1){
	                // 个人用户 能在列表正常展示的简历，才统计
	                $expect  =  $this->select_once('resume_expect',array('uid'=>$data['uid'],'defaults'=>1,'state'=>'1','status'=>'1','r_status'=>'1'),'`id`');
	                
	                if (empty($expect)){
	                    return;
	                }
	            }
	            
	            $data['ctime']  =  time();
	            
	            $this->insert_into('zphnet_user',$data);
	        }
	    }
	}
	/**
	 * 查询进入大厅记录
	 */
	public function getZphnetUser($where = array(),$data = array('resume'=>'','keyword'=>'','photo'=>''))
	{
	    // 求职者大厅
	    if (!empty($data['resume'])){
	        
	        $row  =  $this->select_all('zphnet_user',array('zid'=>$where['zid'],'usertype'=>1,'orderby'=>'ctime','limit'=>$data['resume']),'`uid`');
	        
	        if (!empty($row)){
	            
	            foreach ($row as $v){
	                
	                $uids[]  =  $v['uid'];
	            }
	            
	            include_once('resume.model.php');
	            $resumeM  =  new resume_model($this->db, $this->def);
	            
	            $rwhere   =  array('uid'=>array('in',pylode(',', $uids)),'defaults'=>1,'state'=>'1','status'=>'1','r_status'=>'1');
	            
	            if (!empty($data['keyword'])){
	                
	                $rwhere['name']  =  array('like', $data['keyword']);
	            }
	            
	            $expect   =  $resumeM->getList($rwhere,array('utype'=>'zphnet'));
	            
	            return $expect['list'];
	        }
	    }else{
	        
	        $row  =  $this->select_all('zphnet_user',$where);
	        
	        if (!empty($row)){
	            $u  =  $c  =  array();
	            
	            foreach ($row as $v){
	                
	                if ($v['usertype'] == 1){
	                    $u[]  =  $v['uid'];
	                }elseif ($v['usertype'] == 2){
	                    $c[]  =  $v['uid'];
	                }
	            }
	            if (!empty($c)){
	                
	                $com   =  $this->select_all('company',array('uid'=>array('in',pylode(',', $c))),'`uid`,`name`,`shortname`');
	            }
	            if (!empty($u)){
	                
	                $user  =  $this->select_all('resume',array('uid'=>array('in',pylode(',', $u))),'`uid`,`name`');
	            }
	            
	            foreach ($row as $k=>$v){
	                
	                foreach ($com as $val){
	                    
	                    if ($v['uid'] == $val['uid']){
	                        
	                        if ($val['shortname']){
	                            
	                            $row[$k]['name']  =  $val['shortname'].'进入了大厅';
	                            
	                        }else{
	                            
	                            $row[$k]['name']  =  $val['name'].'进入了大厅';
                            }
	                    }
	                }
	                foreach ($user as $val){
	                    
	                    if ($v['uid'] == $val['uid']){
	                        
	                        $name  =  mb_substr($val['name'], 1, 1, 'utf8');
	                        $row[$k]['name']  = str_replace($name, '*', $val['name']).'进入了大厅';
	                    }
	                }
	            }
	            return $row;
	        }
	    }
	}
	/**
	 * 网络招聘会查看职位记录
	 */
	public function addZphnetLook($data = array()){
	    
	    if (!empty($data)){
	        
	        if (!empty($data['uid'])){
	            
	            $row  =  $this->select_once('zphnet_look',array('uid'=>$data['uid'],'zid'=>$data['zid'],'jobid'=>$data['jobid']));
	        }
	        // 用户登录时，个人查看才记录
	        if (empty($row) && (empty($data['usertype']) || (!empty($data['usertype']) && $data['usertype'] ==1))){
	            
	            $nid  =  $this->insert_into('zphnet_look',$data);
	        }
	        
	        return $nid;
	    }
	}
	/**
	 * 获取招聘会查看职位记录
	 */
	public function getZphnetLook($where = array()){
	    
	    $list  =  $this->select_all('zphnet_look',$where);
	    
	    if (!empty($list)){
	        
	        $j  =  $u  =  $c  =  array();
	        
	        foreach ($list as $v){
	            
	            $j[]  =  $v['jobid'];
	            if ($v['usertype'] == 1){
	                
	                $u[]  =  $v['uid'];
	            }
	            if (!empty($v['comid'])){
	                
	                $c[]  =  $v['comid'];
	            }
	        }
	        if (!empty($j)){
	            $job   =  $this->select_all('company_job',array('id'=>array('in',pylode(',', $j))),'`id`,`name`');
	        }
	        if (!empty($u)){
	            $user  =  $this->select_all('resume',array('uid'=>array('in',pylode(',', $u))),'`uid`,`name`');
	        }
	        if (!empty($c)){
	            $com  =  $this->select_all('company',array('uid'=>array('in',pylode(',', $c))),'`uid`,`name`,`shortname`');
	        }
	        
	        foreach ($list as $k=>$v){
	            
	            if (!empty($job)){
	                foreach ($job as $val){
	                    
	                    if ($v['jobid'] == $val['id']){
	                        
	                        $list[$k]['jobname']  =  $val['name'];
	                    }
	                }
	            }
	            
	            $list[$k]['name']  = '访客';
	            if (!empty($user)){
	                
	                foreach ($user as $val){
	                    
	                    if ($v['uid'] == $val['uid']){
	                        
	                        $name  =  mb_substr($val['name'], 1, 1, 'utf8');
	                        $list[$k]['name']  = str_replace($name, '*', $val['name']);
	                    }
	                }
	            }
	            if (!empty($com)){
	                
	                foreach ($com as $val){
	                    
	                    if ($v['comid'] == $val['uid']){
	                        
	                        if ($val['shortname']){
	                            
	                            $list[$k]['comname']  =  $val['shortname'];
	                            
	                        }else{
	                            
	                            $list[$k]['comname']  =  $val['name'];
	                        }
	                    }
	                }
	            }
	        }
	    }
	    
	    return $list;
	}
	/**
	 * wxapp 参展职位列表
	 */
	public function getZphnetJob($where = array(), $data = array())
	{
	    $return  =  array();
	    
	    if (!empty($where['zid'])){
	        
	        $zphcom  =  $this->select_all('zphnet_com', array('zid'=>$where['zid'],'status'=>1),'`uid`');
	        
	        if (!empty($zphcom)){
	            
	            foreach ($zphcom as $v){
	                
	                $cuid[]  =  $v['uid'];
	            }
	            $jwhere  =  array('uid'=>array('in',pylode(',', $cuid)),'state'=>1,'status'=>0,'r_status'=>1);
	            
	            if (!empty($data['keyword'])){
	                
	                $jwhere['name']  =  array('like',$data['keyword']);
	            }
	            $jwhere['limit']  =  $where['limit'];
	            
	            $job  =  $this->select_all('company_job',$jwhere,'`id`,`uid`,`name`,`exp`,`edu`,`minsalary`,`maxsalary`');
	            
	            if (!empty($job)){
	                
	                foreach ($job as $v){
	                    
	                    $juid[]  =  $v['uid'];
	                }
	                $juid  =  array_unique($juid);
	                
	                $com   =  $this->select_all('company',array('uid'=>array('in',pylode(',', $juid))),'`uid`,`name`,`shortname`');
	                
	                include_once('cache.model.php');
	                $cacheM  =  new cache_model($this->db,$this->def);
	                $cache   =   $cacheM -> GetCache('com');
	                
	                foreach ($job as $k=>$v){
	                    
	                    $job[$k]['exp_n']  =  $cache['comclass_name'][$v['exp']].'经验';
	                    $job[$k]['edu_n']  =  $cache['comclass_name'][$v['edu']].'学历';
	                    
	                    if (!empty($v['minsalary']) || !empty($v['minsalary'])) {
	                        
	                        if(!empty($v['minsalary']) && !empty($v['maxsalary'])){
	                            
	                            $job[$k]['job_salary']  =  '￥'.$v['minsalary'].'-'.$v['maxsalary'].'元/月';
	                            
	                        }elseif (!empty($v['minsalary'])){
	                            
	                            $job[$k]['job_salary']  =  '￥'.$v['minsalary'].'元/月';
	                            
	                        }else{
	                            
	                            $job[$k]['job_salary']  =  '面议';
	                        }
	                    }else{
	                        
	                        $job[$k]['job_salary']      =  '面议';
	                    }
	                    
	                    foreach ($com as $val){
	                        
	                        if ($v['uid'] == $val['uid']){
	                            
	                            if ($val['shortname']){
	                                
	                                $job[$k]['comname']  =  $val['shortname'];
	                                
	                            }else {
	                                
	                                $job[$k]['comname']  =  $val['name'];
	                            }
	                        }
	                    }
	                }
	            }
	        }
	        if (!empty($job)){
	            
	            $return  =  $job;
	        }
	        
	        return $return;
	    }
	}
	/**
	 * 推荐企业类别列表
	 */
	public function getClassList($where = array(), $data = array())
	{
	    
	    $list  =  $this->select_all('zphnet_class',$where);
	    
	    return $list;
	}
	/**
	 * 展位分区类别
	 */
	public function getClass($where = array())
	{
	    
	    $list  =  $this->select_once('zphnet_class',$where);
	    return $list;
	}
	/**
	 * 添加或更新展位分区
	 * $addData 	提交分类数据
	 * $whereData 	更新分类查询条件 
	 */
	function addClass($addData=array(),$whereData = array()){
		
		if(!empty($whereData)){
			if($addData['name']){//修改名称
				$type	=	'名称';
			}else{
				unset($addData['name']);
			}
			if($addData['sort']){//修改排序
				$type	=	'排序';
			}else{
				unset($addData['sort']);
			}
			$this->update_once('zphnet_class',$addData,$whereData);
			$showid	 =  $whereData['id'] ? "(ID:".$whereData['id'].")" : '';
			$this->adminLog('网络招聘会展位分区类别'.$showid.$type.'修改成功');
		}else{
			$name				=	array();
			foreach ($addData['name'] as $val){
				if($val){
					$name[]		= 	$val;
				}
			}

			if($addData['keyid']){
				$where['keyid'] =	$addData['keyid'];
			}
			if(count($name)){
				$where['name']  =	array('in',"'".@implode("','",$name)."'");
			}
			//检查提交的类别名称是否有同名
			$class			    =	$this->getClassList($where);
			$valueData			=	array();
			
			if(empty($class)){//没有同名类则正常添加
				if($addData['ctype'] == '1'){//添加的是一级分类
					foreach ($name as $key => $val){
			            $valueData[$key]['name']		= $val;
			            
			        }
			    }else{//添加二级分类
					foreach ($name as $key => $val){
						$valueData[$key]['name'] 	= $val;
			            $valueData[$key]['keyid'] 	= intval($addData['keyid']);
			        }
			    }
				$nid 			=	$this->DB_insert_multi('zphnet_class',$valueData);
				$return['msg']	=	$nid ? 2 : 3;
				$this 			->  adminLog('网络招聘会展位分区类别添加成功');
			}else{//有同名类，给出提示
				$return['msg']	=	1;
			}
		}
		return	$return;
	}
	/**
	 * 修改企业推荐类别
	 */
	public function upClass($where = array(), $data = array())
	{
	    if (!empty($data)){
	        
	        $this->update_once('zphnet_class', $data, $where);
	    }
	}
	/**
	 * 删除招聘会企业推荐类别
	 */
	public function delClass($delId){
	    
	    if (empty($delId)) {
	        
	        $return     =   array( 'errcode' => 8, 'msg' => '请选择要删除的数据！');
	        
	    } else {
	        
	        if (is_array($delId)) {
	            
	            $delId  =   pylode(',', $delId);
	            
	            $return['layertype']    =   1;
	            
	        } else {
	            
	            $return['layertype']    =   0;
	        }
	        
	        $id					=	array();
	        $sclass				=	$this	->	select_all('zphnet_class',array('id' => array('in', $delId)),'id');
	        foreach ($sclass as $key => $value) {
	            $id[]			=	$value['id'];
	        }
	        $ids				=	$this->sonclass('zphnet_class',$id);//获取当前项及其所有子类的id集合
	        if(count($ids)){
	            $result			=	$this->delete_all('zphnet_class',array('id'=>array('in',pylode(',',$ids))),'');
	        }
	        $return['errcode']	=	$result ? '9' :'8';
	        $return['msg']		=	$result ? '网络招聘会展位分区类别删除成功！' : '删除失败！';
	    }
	    
	    return $return;
	}
	function sonclass($table,$id=array()){
	    $ids	=	array();
	    if(count($id)){
	        $class	=	$this	->	select_all($table,array('keyid'=>array('in',pylode(',',$id))),'id');
	        if($class&&is_array($class)){
	            foreach($class as $val){
	                $ids[]	=	$val['id'];
	            }
	        }
	        $ids	=	array_merge($id,$ids);
	    }
	    return $ids;
	}
	/*
	 * 添加管理员日志
	 */
	function adminLog($content, $opera = '', $type = '', $opera_id=''){
	    require_once('log.model.php');
	    $logM	=	new log_model($this->db,$this->def);
	    return	$logM	->	addAdminLog($content, $opera = '', $type = '', $opera_id='');
	}
	/**
	 * 创建视频招聘会，同步数据至招聘会云平台
	 */
	function syncZphVideo($data = array()){
		
		if (!empty($data)){
			
			$authId		=	$data['zphWebID'];
			$authKey	=	$data['zphWebKey'];
			
			$zphId		=	$data['zphId'];
			 
			//开始请求
			$zphNetInfo	=	$this->getInfo(array('id' => $zphId));
    		$postjson['zphnetInfo']		=	json_encode($zphNetInfo);	// 网络招聘会信息
    		$zphNetClass=	$this->getClassList();
    		$postjson['zphnetClass']	=	json_encode($zphNetClass);	// 网络招聘会分类信息
    		
    		$comNum		=	$this->select_num('zphnet_com', array('zid' => $zphId));
			
			$size 		= 	10; 
			
			//循环次数 
			$page 		= 	ceil($comNum/$size); 
    		
			$zphNetCom	=	$this->getZphnetComList(array('zid' => $zphId, 'issync' => '0', 'orderby' => 'uid,desc', 'limit' => $size), array('field' => '`uid`,`zid`,`ctime`,`status`,`statusbody`,`did`,`price`,`zw`'));
			  
						
			if (!empty($zphNetCom)){	// 网络招聘会参会企业
				
				$comuid	=	array();
				
				foreach ($zphNetCom as $key => $value) {
					$comuid[]	=	$value['uid'];
				}
				
				$member		=	$this->select_all('member', array('uid' => array('in', pylode(',', $comuid)),'status'=> '1'), '`uid`,`moblie`');
				$company	=	$this->getSyncCompanyData(array('uid' => array('in', pylode(',', $comuid)), 'r_status' => '1', ));
				$job		=	$this->getSyncJobData(array('uid' => array('in', pylode(',', $comuid)), 'state' => '1', 'status' => '0', 'r_status' => '1'));
				
				$postjson['member']		=	json_encode($member);		 
				$postjson['company']	=	json_encode($company);		 
				$postjson['job']		=	json_encode($job);		 
				$postjson['zphnetCom']	=	json_encode($zphNetCom);	
			}
			 
    		$postjson['id'] 		=	$zphId;
    		$postjson['authid'] 	=	$authId;
    		$postjson['authkey'] 	=	$authKey;
    		   
    		//CURL POST 数据
        	$url 		=	'https://www.douxu.com/api/zphnetv/index.php?c=syncVideoZph';//接收地址
        	
        	$return		=	CurlPost($url,$postjson);
        	
			$reponse	=	json_decode($return, true);
			
			 
        	if ($reponse['error'] == 1){

        		$this->update_once('zphnet_com', array('issync' => '1'), array('zid' => $zphId, 'uid' => array('in', pylode(',', $comuid))));
        		
        		if($zphNetInfo['issync'] == '0'){
        			
        			$this->update_once('zphnet', array('issync' => '1'), array('id' => $zphId));
        		}
        		
	        	if (!empty($reponse['data']['xcxqrcode'])){
	        		
	        		$this->update_once('zphnet', array('xcxqrcode' => $reponse['data']['xcxqrcode']), array('id' => $zphId));
	        	}

        		if ($data['page'] < $page){

        			$count	=	$data['page'] * $size;
        			return array('status' => '3', 'page' => $data['page'] + 1, 'msg' => '已同步参会企业'.$count.'家，请稍候。。。');
	        	}
        	}
        	
        	return $reponse;
		}
		
	}
	
	/**
	 * @desc 获取同步企业信息数据
 	 * @param $where
	 */
	function getSyncCompanyData($where = array()){
		
		if (!empty($where)){
			
            $cache	=	$this -> getCacheClass(array('hy','city','com'));
			
			$List 	= 	$this->select_all('company', $where);
			
			if (!empty($List)) {
				
				foreach ($List as $key => $value) {
					$List[$key]['hy']			=	$cache['industry_name'][$value['hy']];
					$List[$key]['pr']			=	$cache['comclass_name'][$value['pr']];
					$List[$key]['provinceid']	=	$cache['city_name'][$value['provinceid']];
					$List[$key]['cityid']		=	$cache['city_name'][$value['cityid']];
					$List[$key]['three_cityid']	=	$cache['city_name'][$value['three_cityid']];
					$List[$key]['mun']			=	$cache['comclass_name'][$value['mun']];
					if($value['logo']){
					    $List[$key]['logo']	    =	checkpic($value['logo']);
					}
				}
			}
			
			return $List;
		}
	}
	
	/**
	 * @desc 获取同步职位信息数据
 	 * @param $where
	 */
	function getSyncJobData($where = array()){
		
		if (!empty($where)){
			
            $cache	=	$this -> getCacheClass(array('job','hy','city','com'));
			
			$List 	= 	$this->select_all('company_job', $where);
			
			if (!empty($List)) {
				
				foreach ($List as $key => $value) {
					$List[$key]['hy']			=	$cache['industry_name'][$value['hy']];
					$List[$key]['job1']			=	$cache['job_name'][$value['job1']];
					$List[$key]['job1_son']		=	$cache['job_name'][$value['job1_son']];
					$List[$key]['job_post']		=	$cache['job_name'][$value['job_post']];
					$List[$key]['provinceid']	=	$cache['city_name'][$value['provinceid']];
					$List[$key]['cityid']		=	$cache['city_name'][$value['cityid']];
					$List[$key]['three_cityid']	=	$cache['city_name'][$value['three_cityid']];
					
 					$List[$key]['number']		=	$cache['comclass_name'][$value['number']];
 					$List[$key]['exp']			=	$cache['comclass_name'][$value['exp']];
 					$List[$key]['report']		=	$cache['comclass_name'][$value['report']];
 					$List[$key]['edu']			=	$cache['comclass_name'][$value['edu']];
 					$List[$key]['marriage']		=	$cache['comclass_name'][$value['marriage']];
 					$List[$key]['age']			=	$cache['comclass_name'][$value['age']];
 					$List[$key]['pr']			=	$cache['comclass_name'][$value['pr']];
 					$List[$key]['mun']			=	$cache['comclass_name'][$value['mun']];
 					
 					$List[$key]['com_provinceid']	=	$cache['city_name'][$value['com_provinceid']];
				}
			}
			
			return $List;
		}
	}
	
	
	/**
     * @desc   获取缓存数据
     * @param   array $options
     * @return  array $cache
     */
    private function getCacheClass($options)
    {
             
        include_once ('cache.model.php');
        
        $cacheM     =   new cache_model($this->db, $this->def);
        
        $cache      =   $cacheM -> GetCache($options);
        
        return $cache;
     
    }
}
?>